package com.ssm.service.Impl;

import com.ssm.entity.*;
import com.ssm.mapper.*;
import com.ssm.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 使用87gou表
 */
@Service
public class UserRoleServiceImpl implements UserRoleService {

    @Autowired
    private SysUserRoleMapper userRoleMapper;

    @Autowired
    private SysRoleResourceUrlMapper roleResourceUrlMapper;

    /**
     * 获取所有角色信息
     * @return
     */
    @Override
    public Set<SysRole> getAllRoles() {
        Set<SysRole> allRoles = userRoleMapper.getAllRoles();
        return allRoles;
    }

    /**
     * 获取某个角色的所有资源信息
     * @param role
     * @return
     */
    @Override
    public List<SysRoleResourceUrl> getAllResourceURLByRole(String role) {
        List<SysRoleResourceUrl> resources = roleResourceUrlMapper.getAllResourceURLByRole(role);
        return resources;
    }

    /**
     * 获取所有角色的所有资源  角色 1 - 资源 n
     * @return
     */
    @Override
    public List<List<SysRoleResourceUrl>> getAllResourceURLAndAllRoles() {
        List<List<SysRoleResourceUrl>> allRoleAndResources = new ArrayList<>();
        Set<SysRole> allRoles =  getAllRoles();
        for (SysRole Role : allRoles){
            List<SysRoleResourceUrl> resourceURLs = getAllResourceURLByRole(Role.getRoleName());
            allRoleAndResources.add(resourceURLs);
        }
        return allRoleAndResources;
    }

}
